package com.zyz.K_集合.Set接口实现类三TreeSet;

import java.util.TreeSet;

/**
 * @author: vick
 * @Date: 2025/3/30
 * @Description:
 * @version: 1.0
 */
public class Demo1 {
    public static void main(String[] args) {
        TreeSet<Integer> treeSet = new TreeSet<>();
        treeSet.add(1);
        treeSet.add(3);
        treeSet.add(5);
        treeSet.add(7);
        treeSet.add(9);
        System.out.println(treeSet);

        System.out.println("======");
        System.out.println(treeSet.first());
        System.out.println(treeSet.last());

        System.out.println("======");
        System.out.println(treeSet.higher(5));//7
        System.out.println(treeSet.lower(5));//3
        System.out.println(treeSet.floor(4));//3
        System.out.println(treeSet.ceiling(5));//7

        System.out.println("======");

        System.out.println(treeSet.headSet(5));
        System.out.println(treeSet.headSet(5,true));

        System.out.println("======");
        System.out.println(treeSet.tailSet(5));
        System.out.println(treeSet.tailSet(5, false));

        System.out.println("======");
        System.out.println(treeSet.subSet(3,9));
        System.out.println(treeSet.subSet(3, true,9, true));
        System.out.println(treeSet.subSet(3, false,9, true));
    }
}
